<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel common\models\PaintingSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '作品管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="painting-index">

    <?php //echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('添加作品', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'category_id' => [
                'attribute' => 'category_id',
                'value' => function($model){
                    $cate = $model->category;
                    if(!empty($cate)){
                        return $cate->category;
                    }else{
                        return '未分类';
                    }
                }
            ],
            'user_id' => [
                'attribute' => 'user_id',
                'value' => function($model){
                    $admin = $model->admin;
                    if(!empty($admin)){
                        return $admin->username;
                    }else{
                        return '无名';
                    }
                }
            ],
            'image' => [
                'attribute' => 'image',
                'format' => ['raw'],
                'value' => function($model){
                    return Html::img($model->image,['height'=>'50px']);
                },
            ],
            'title' => [
                'attribute' => 'title',
                'format' => 'raw',
                'value' => function ($model) {
                    return '<a href="' . \yii\helpers\Url::to(['post/view', 'id' => $model->id]) . '">' . $model->title . '</a>';
                }
            ],
            'describe:ntext',
            'status' => [
                'attribute' => 'status',
                'value' => function ($model) {
                    return $model->status == 0 ? '显示' : '不显示';
                },
                'filter' => ['0' => '显示', '1' => '不显示'],
            ],
            'show_banner',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
